home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14053 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Character string
  5. Date: 11 Apr 1996 15:55:25 GMT
  6. Organization: OpenVision
  7. Message-ID: <4kja1d$7fm@spanky.pls.ov.com>
  8. References: <4kil74$8i7@Tandem1.opennet.net.au>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 8i7@Tandem1.opennet.net.au, george@opennet.net.au (Kenneth H Smith) writes:
  13. >How do I do a similar statement in C to the Pascal code:
  14. >
  15. >If Ch IN ['a','A'] THEN
  16. >
  17. >I want to execute a piece of code when a particular character is entered
  18. >from the keyboard.
  19. >
  20. >I know I can use if (ch=='a') && (ch=='A') but was looking for something
  21. >a little more ellegant.
  22. >
  23. >Thanks,
  24. >
  25. >Ken Smith.
  26. >
  27.  
  28.  
  29. For small tests (like two characters) you cannot beat the if test.  For
  30. filtering among many characters, the code can be made much more understandable
  31. using the switch() statement.  switch() allows you to identify various
  32. responses to input values on a case by case basis.  See your local C book.
  33.  
  34.             Fletcher.Glenn@ov.com
  35.  
  36.  
  37.